home *** CD-ROM | disk | FTP | other *** search
-
- /**
-
- # # # #
- ## ## # # # ##### # # # ###### ##### #### ######
- # # # # # # # # # # # # # # # #
- # # # # # # # # # # ##### # # #### #####
- # # # # # # # # # # ##### # #
- # # # # # # # # # # # # # # #
- # # #### ###### # # # ###### # # #### ######
-
- #####
- # # # # #### ##### ###### # #
- # # # # # # ## ##
- ##### # #### # ##### # ## #
- # # # # # # #
- # # # # # # # # #
- ##### # #### # ###### # #
-
- Copyright: Robert Grant, 1993
-
- **/
-
- #define _XOPEN_SOURCE
- #define _ALL_SOURCE
-
- /* includes */
-
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- #include <string.h>
-
- #include <graphics.h>
- #include <messages.h>
- #include <eventHandler.h>
- #include <clientManager.h>
- #include <objectManager.h>
-
- #include <ext_bullet.h>
-
- extern double matrix[4];
-
- int initBullet(object_t *theBullet, bulletExt_t *bulletData,
- init_t *event) {
-
- serverEventMsg_t ev;
- object_t *parent;
- createObject_t object;
- changePanel_t panel;
- mat rot;
- parent = event->parent;
- if (bulletData->fired)
- return 0;
- bulletData->fired = 2;
- returnrotatematrix(&rot, 0, parent->coords.rot.y, 0);
- matrix[0] = 0;
- matrix[1] = 0;
- matrix[2] = 0.7;
- matrix[3] = 1;
- transform(&rot);
- theBullet->coords.loc.x = parent->coords.loc.x - matrix[0];
- theBullet->coords.loc.z = parent->coords.loc.z + matrix[2];
- theBullet->coords.rot.y = parent->coords.rot.y;
- theBullet->coords.rot.x = 0;
- theBullet->coords.loc.y = parent->coords.loc.y + 0.9;
- strcpy(object.name, theBullet->name);
- strcpy(object.type, theBullet->type);
- memcpy(&object.coords, &theBullet->coords, sizeof(viewpoint));
- object.class = MANAGED;
- composeServerEventMessage(&ev, CREATE, OBJECT, NULL, &object);
- broadcast(SERVEREVENT, sizeof(ev), &ev);
- panel.type = PANEL_VALUE;
- strcpy(panel.name, "dactyl:bullet");
- panel.value = 0;
- composeServerEventMessage(&ev, CHANGE, CHG_PANEL, "dactyl", &panel);
- sendMessage(theBullet->socket, SERVEREVENT, sizeof(serverEventMsg_t), &ev);
- theBullet->collider = createCollider();
- if (!theBullet->collider) {
- fprintf(stderr, "Can't get space for collision detection!\n");
- return 0;
- }
- theBullet->collider->obj = theBullet;
- theBullet->collider->type = OBJ_DYNAMIC;
- theBullet->collider->boundType = BOX;
- theBullet->collider->box[0].x = -0.04;
- theBullet->collider->box[0].y = -0.04;
- theBullet->collider->box[0].z = -0.04;
- theBullet->collider->box[1].x = 0.04;
- theBullet->collider->box[1].y = 0.04;
- theBullet->collider->box[1].z = 0.04;
- addCollider(theBullet->collider);
- return 1;
- }
-
- int moveBullet(object_t *theBullet, bulletExt_t *bulletData,
- move_t *event) {
-
- serverEventMsg_t ev;
- moveEvent_t move;
- changePanel_t panel;
- if (bulletData->fired == 2) {
- if (theBullet->coords.loc.y < 0) {
- bulletData->fired = 1;
- }
- else {
- theBullet->coords.loc.x -= sin(RADIANS(theBullet->coords.rot.y))/8.0;
- theBullet->coords.loc.z += cos(RADIANS(theBullet->coords.rot.y))/8.0;
- theBullet->coords.loc.y -= theBullet->coords.rot.x;
- theBullet->coords.rot.x += 0.001;
- strcpy(move.name, theBullet->name);
- memcpy(&move.coords, &theBullet->coords, sizeof(viewpoint));
- composeServerEventMessage(&ev, MOVE, 0, NULL, &move);
- broadcast(SERVEREVENT, sizeof(serverEventMsg_t), &ev);
- return;
- }
- }
- if (bulletData->fired == 1) {
- ev.type = DELETE;
- strcpy(ev.event.deleteEvent.name, theBullet->name);
- broadcast(SERVEREVENT, sizeof(serverEventMsg_t), &ev);
- panel.type = PANEL_VALUE;
- strcpy(panel.name, "dactyl:bullet");
- panel.value = 1;
- composeServerEventMessage(&ev, CHANGE, CHG_PANEL, "dactyl", &panel);
- sendMessage(theBullet->socket, SERVEREVENT, sizeof(serverEventMsg_t), &ev);
- removeCollider(theBullet->collider);
- free(theBullet->collider);
- theBullet->collider = NULL;
- bulletData->fired = 0;
- }
- }
-
- int checkBulletCollision(object_t *theBullet, bulletExt_t *bulletData,
- collideEvent_t *event) {
-
- serverEventMsg_t ev;
- event_t term;
- object_t *theCollider;
- theCollider = event->obj;
- if (theBullet->parent == theCollider)
- return 0;
- if (theBullet->parent == theCollider->parent)
- return 0;
- bulletData->fired = 1;
- term.type = TERM_NOTIFY_EVENT;
- sendEventByRef(theBullet->parent, &term);
- return 1;
- }
-
- int addBulletExtensions(object_t *theObject) {
-
- bulletExt_t *temp = NULL;
- if ((temp = (bulletExt_t *)malloc(sizeof(bulletExt_t))) == NULL) {
- fprintf(stderr, "Can't allocate space for bullet extension!\n");
- return 0;
- }
- addEventHandler(theObject, MOVE_EVENT, temp, moveBullet);
- addEventHandler(theObject, INIT_EVENT, temp, initBullet);
- addEventHandler(theObject, COLLISION_NOTIFY_EVENT, temp, checkBulletCollision);
- }
-
- int installBulletExtensions() {
-
- installEventHandlerCreator("bullet", addBulletExtensions);
- }
-